<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>首页</title>
    <%@include file="/resources/common/head.jsp" %>
    <script src="/resources/js/wetravel.js" type="text/javascript"></script>
    <script src="/resources/css/wetravel.css" type="text/css"></script>
</head>
<body>
<h2>Hello World!</h2>
<c:if test="${sessionScope.currentUser!=null}">
    欢迎回来，<a href="/user/userInfo">${sessionScope.currentUser.username}</a> &nbsp;<a href="javascript:void(0);" onclick="logout()">退出</a>
</c:if>
<c:if test="${sessionScope.currentUser==null}">
    <a href="/user/register">注册</a>
    <a href="/user/login">登录</a>
    <a href="/user/forget">忘记密码</a>
</c:if>
<br>
<a href="/manage/user/login">管理员入口</a>
</body>

<script type="text/javascript">
    function logout(){
        var status = 1;
        //发送请求
        $.ajax({
            type:"post",
            url:"/user/logout.do",      // 这里是提交到什么地方的url
            dataType:"json",
            async: false,       //设置ajax请求为同步，防止发送请求后执行success代码异常
            success:function(res){
                if(res.status==0){
                    status = 0;
                }
                alert("msg:"+res.msg);
            },
            error:function(res){
                if(res.status==0){
                    status = 0;
                }
                alert("msg:"+res.msg);
            }
        });
        if(status == 0) {
            setTimeout("javascript:location.href=wetravel.URL.index()", 1);
        }
    }
</script>
</html>
